#include "AHT10.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static uint8_t AHT10_close(th_sensor_handle *handle)
{
    printf("I2C Uninit\r\n");
    printf("AHT10_close\r\n");
    return TH_SENSOR_OK;
}

static uint8_t AHT10_open(th_sensor_handle *handle)
{
    printf("AHT10_open\r\n");
    printf("I2C Init: %s\r\n", AHT10_PORT);
    return TH_SENSOR_OK;
}

static uint8_t AHT10_read(th_sensor_handle *handle)
{
    printf("AHT10_read\r\n");
    printf("I2C read addr:%#X reg:%#X\r\n", AHT10_ADDR, AHT10_REG);
    handle->temp = 26.0f;
    handle->humi = 68.0f;
    return TH_SENSOR_OK;
}

th_sensor_handle *AHT10_new()
{
    th_sensor_handle *aht10 = (th_sensor_handle *)malloc(sizeof(th_sensor_handle));
    if (aht10 == NULL)
        return NULL;
    memset(aht10, 0x00, sizeof(th_sensor_handle));
    aht10->close = AHT10_close;
    aht10->open = AHT10_open;
    aht10->read = AHT10_read;
    aht10->temp = 0.0f;
    aht10->humi = 0.0f;
    return aht10;
}